<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <%- include('./header.ejs') -%>
        <h1>1111111</h1>
        <h1>
            <%- title -%>
        </h1>
        <button id='send'>发送消息到服务器</button>
        <div>
            <h3>服务器响应的消息：</h3>
            <i id='msg'></i>
        </div>
</body>
<script crossorigin="anonymous"
    integrity="sha512-2RDFHqfLZW8IhPRvQYmK9bTLfj/hddxGXQAred2wNZGkrKQkLGj8RCkXfRJPHlDerdHHIzTFaahq4s/P4V6Qig=="
    src="//lib.baomitu.com/socket.io/3.1.3/socket.io.js"></script>
<script>
    var send = document.querySelector('#send');
    var msg = document.querySelector('#msg');

    let socket = io.connect('ws://192.168.42.162:3000');
    socket.on('serverEmit',function(data){
       console.log(data);
   });
    socket.on('sendAll',function(data){
       console.log(data);
   });
    send.addEventListener("click", () => {
        console.log('点击了发送消息！');
        socket.emit('sendMsg','message');
    })
</script>

</html>